<!--
 * @Author: 张久冬
 * @Date: 2022-01-06 14:45:16
 * @
# Description:
-->
<template>
  <div class="baseEcharts">
    <div ref="echartDivRef" :style="{ width: width, height: height }"></div>
  </div>
</template>

<script lang="ts" setup>
import type { EChartsOption } from 'echarts'
import { ref, onMounted, defineProps, withDefaults, watchEffect } from 'vue'
import useEcharts from '../hooks/useEcharts'

const echartDivRef = ref<HTMLElement>()
// 定义props
const props = withDefaults(
  defineProps<{
    options: EChartsOption
    width?: string
    height?: string
  }>(),
  {
    width: '100%',
    height: '360px'
  }
)
onMounted(() => {
  const { echartsInstance, setOptions, updateSize } = useEcharts(
    echartDivRef.value
  )
  watchEffect(() => {
    setOptions(props.options)
  })
})
</script>

<style scoped></style>
